package com.hook3.pianke.Adapter;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hook3.pianke.domain.RadioInfo;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * 给大图轮播viewpager设置adapterr
 */
public class RadioViewPagerAdapter extends PagerAdapter {

    private ArrayList<RadioInfo.RadioCauousel> carouselDatasAdapter;
    private Activity activity;

    public RadioViewPagerAdapter(ArrayList<RadioInfo.RadioCauousel> carouselDatas, Activity activity) {
        this.carouselDatasAdapter = carouselDatas;
        this.activity = activity;

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        ImageView imageView = new ImageView(activity);

        ImageOptions imageOptions = new ImageOptions.Builder().build();
        x.image().bind(imageView,carouselDatasAdapter.get(position).img,imageOptions);

        container.addView(imageView);
        return imageView;
    }

    @Override
    public int getCount() {
        return carouselDatasAdapter.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
